﻿
@{
    Layout = null;
}

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>产品零件材料</title>
    <link href="~/Content/style.css" rel="stylesheet" type="text/css" />
    <style>
        .xh ul li:first-child{
            width:15px !important;
            line-height:70px;
        }
        input[name='rawtype']{
            line-height:70px;
        }
    </style>
</head>

<body>
    <div class="pro_r">
        <div class="pro_top table1">
            <h3><span>材料信息</span></h3>
            <table></table>
            <p><a id="add">添加材料</a><a id="del">修改材料</a><a>删除材料</a></p>
        </div>
    </div>
    <div id="box_add4">
        <h2>添加材料<span>×</span></h2>
        <ul class="mc">
            <li style="width:170px;"><p>材料名称</p><input type="hidden" name="raw_id"><input style="width:120px;" readonly type="text" name="raw_name" required data-type="text" maxlength="50" data-error="材料名称不能为空且长度不能超过50个字符！" /><a class="jb">>></a></li>
            <li><p>规格</p><input name="raw_guige" readonly type="text" data-type="text" data-error="材料规格长度不能超过50个字符！" /></li>
            <li><p>单价(元/kg)</p><input name="price" readonly type="text" required data-type="number" data-error="单价不能为空且必须为数字！" /></li>
            <li><p>下单数量</p><input name="qty" type="text" required data-type="number" data-error="下单数量不能为空且必须为数字！" /></li>
            <li><p>单件可回收废料(kg)</p><input type="text" name="tfl_weight"  required data-type="number" data-error="单件可回收废料不能为空且必须为数字！"  /></li>
        </ul>

        <div class="xh">
            <em>材料型号</em>
            <ul><li><input type="radio" name="rawtype" value="1" /></li><li class="li_1"><i>δ 板材</i></li><li><p>厚(mm)</p><input type="text" name="p1" required data-type="number" data-error="板材厚度不能为空且必须为数字！" /></li><li><p>长(mm)</p><input type="text" name="p2" required data-type="number" data-error="板材长度不能为空且必须为数字！"  /></li><li><p>宽(mm)</p><input type="text" name="p3"  required data-type="number" data-error="板材宽度不能为空且必须为数字！"  /></li></ul>
            <ul><li><input type="radio" name="rawtype" value="2" /></li><li class="li_1"><i>Φ 棒料</i></li><li><p>直径(mm)</p><input type="text" name="p1" required data-type="number" data-error="棒料直径不能为空且必须为数字！"  /></li><li><p>长(mm)</p><input type="text" name="p2" required data-type="number" data-error="棒料长度不能为空且必须为数字！"   /></li></ul>
            <ul><li><input type="radio" name="rawtype" value="3" /></li><li class="li_1"><i>Φ 圆管料</i></li><li><p>外径(mm)</p><input type="text" name="p1" required data-type="number" data-error="圆管料外径不能为空且必须为数字！"   /></li><li><p>内径(mm)</p><input type="text" name="p2" required data-type="number" data-error="圆管料内径不能为空且必须为数字！"   /></li><li><p>长度(mm)</p><input type="text"  name="p3" required data-type="number" data-error="圆管料长度不能为空且必须为数字！"  /></li></ul>
            <ul><li><input type="radio" name="rawtype" value="4" /></li><li class="li_1"><i>□ 方管料</i></li><li><p>长(mm)</p><input type="text" name="p1" required data-type="number" data-error="方管料长度不能为空且必须为数字！"   /></li><li><p>宽(mm)</p><input type="text" name="p2" required data-type="number" data-error="方管料宽度不能为空且必须为数字！"   /></li><li><p>壁厚(mm)</p><input type="text"  name="p3" required data-type="number" data-error="方管料壁厚不能为空且必须为数字！"   /></li><li><p>长度(mm)</p><input type="text"  name="p4" required data-type="number" data-error="方管料长度不能为空且必须为数字！"   /></li></ul>
            <div style="width:20px;text-align:left;margin-right:10px;display:inline-block;"><input type="radio" name="rawtype" value="5" /></div><h3 style="display:inline-block;">特殊钢（角钢、槽钢、H型钢、六角、铝型材等）</h3>
            <ul class="ts">
                <li class="li_1"><i>材料规格</i></li>
                <li><input style="width:316px;" type="text"  name="guige" required data-type="text" maxlength="50" data-error="特殊钢规格不能为空且长度不能超过50个字符！"   /></li>
                <li><span>长度</span><input type="text" name="p1" required data-type="number" data-error="特殊钢长度不能为空且必须为数字！" /><span>毫米</span><span>单价</span><input type="text" /><span>元/kg</span></li>
                <li><span>单件表面积</span><input type="text" /><span>平方米</span></li>
            </ul>
            <div class="clear"></div>
            <div style="width:20px;text-align:left;margin-right:10px;display:inline-block;"><input type="radio" name="rawtype" value="6"/></div><h3 style="display:inline-block;margin-top:10px;">毛坯或不规则材料</h3>
            <ul class="ts" style="height:30px;">
                <li class="li_1"><i>规格型号</i></li>
                <li><input type="text" /></li>
                <li><span>单重</span><input type="text" /><span>kg</span><span>单件表面积</span><input type="text" /><span>平方米</span></li>
            </ul>
        </div>
        <p class="bt"><input type="submit" class="jb" value="保存" onclick="onSaveRaw();" /><input class="jb" type="button" value="返回" /></p>
    </div>
    <div id="box_sel">
        <h2>选择材料<span>×</span></h2>
        <iframe src="/Product/SearchRaw" width="100%" height="100%" frameborder="0"></iframe>
    </div>



    <script src="~/Scripts/jquery-1.10.2.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
    <script src="~/Scripts/bootstrap-table.js"></script>
    <script src="~/Scripts/locale/bootstrap-table-zh-CN.js"></script>
    <script src="~/Scripts/uilts.js"></script>
    <script>
        $(function () {
            $('.table1 tr:even').find('td').css("background", "#e9f3ff");
            $('.table1 tr').click(function () {
                $('.table1 tr').removeClass("act");
                $(this).addClass("act");
            });

            $("#box_add4 input[type='radio']").change(function () {
                $("div.xh input[type='text']").attr("disabled", true);
                var value = parseInt(this.value);
                if (value > 0 && value <= 4) {
                    $(this).parent().parent().find("input[type='text']").attr("disabled", false);
                } else {
                    $(this).parent().next().next().find("input[type='text']").attr("disabled", false);
                }
            });
        });
    </script>
    <script>
        $(function () {
            fn($('#add'), $('#box_add4'));
            fn($('#del'), $('#box_add4'));
            fn($('#add_1'), $('#box_add5'));
            fn($('#del_1'), $('#box_add5'));

            function fn(oA, oB) {
                oA.click(function () {
                    oB.css("display", "block");
                });
                oB.find('p input').eq(1).click(function () {
                    oB.css("display", "none");
                });
                oB.find('h2 span').click(function () {
                    oB.css("display", "none");
                });
            }

            $('#box_add4 .mc a').click(function () {
                $('#box_sel').css("display", "block");
            });
            $('#box_sel').find('p a').click(function () {
                $('#box_sel').css("display", "none");
            });
            $('#box_sel').find('h2 span').click(function () {
                $('#box_sel').css("display", "none");
            });

            $('#box_add5 a').click(function () {
                $('#box_sel_1').css("display", "block");
            });
            $('#box_sel_1').find('p a').click(function () {
                $('#box_sel_1').css("display", "none");
            });
            $('#box_sel_1').find('h2 span').click(function () {
                $('#box_sel_1').css("display", "none");
            });
        });
    </script>

    <script>
        var productid = GetQueryString("productid");
        var partid = GetQueryString("partid");

        var $table = $('table');
        function InitTable(pageIndex, pageSize) {
            if (typeof pageIndex == "object") {
                pageIndex = undefined;
            }
            $table.bootstrapTable('destroy');
            $table.bootstrapTable({
                method: "post",  //使用get请求到服务器获取数据
                url: "/product/PartMateriallistdata", //获取数据的Servlet地址
                striped: true,  //表格显示条纹
                pagination: true, //启动分页
                pageSize: pageSize == null ? 10 : pageSize,  //每页显示的记录数
                pageNumber: pageIndex == null ? 1 : pageIndex, //当前第几页
                pageList: [10, 20, 50, 100, 250],  //记录数可选列表
                search: false,  //是否启用查询
                showColumns: false,  //显示下拉框勾选要显示的列
                showRefresh: false,  //显示刷新按钮
                sidePagination: "server", //表示服务端请求
                sortName: "ID",
                //设置为undefined可以获取pageNumber，pageSize，searchText，sortName，sortOrder
                //设置为limit可以获取limit, offset, search, sort, order
                queryParamsType: "undefined",
                queryParams: function queryParams(params) {   //设置查询参数
                    var param = {
                        PageIndex: params.pageNumber,
                        PageSize: params.pageSize,
                        sorter: params.sortName + " " + params.sortOrder,
                        productid: productid,
                        partid: partid
                    };
                    return param;
                },
                columns: [
                    {
                        field: 'Raw_name',
                        title: "材料名称",
                        align: 'center',
                        valign: 'middle'
                    },
                    {
                        field: 'Raw_guige',
                        title: '材料规格',
                        align: 'center',
                        valign: 'middle'
                    },
                    {
                        field: 'Qty',
                        title: '数量',
                        align: 'center',
                        valign: 'middle'
                    },
                    {
                        field: 'TotalWeight',
                        align: 'center',
                        title: '总重量',
                        valign: 'middle'
                    }

                ],
                onLoadSuccess: function () {
                    $('table tr:even').find('td').css("background", "#e9f3ff");
                    $('table tr').click(function () {
                        uncheckAll($table);
                        $('table tr').removeClass("act");
                        $(this).addClass("act");
                        $table.bootstrapTable('check', $(this).attr("data-index"));
                    });
                }
            });
        }
        InitTable();
    </script>
    <script>
        function partSelectCallback(data) {
            if (data != null) {
                $("#box_sel").css("display", "none");
                //$("input[name='gy_id']").val(data.id);
                //$("input[name='gy_name']").val(data.gy);
                $("#box_add4 input[name='raw_id']").val(data.id);
                $("#box_add4 input[name='raw_name']").val(data.name);
                $("#box_add4 input[name='raw_guige']").val(data.guige);
                $("#box_add4 input[name='price']").val(data.price);
            }
        }

        function CloseSelectPartDiv() {
            $("#box_sel").css("display", "none");
        }

        function onSaveRaw() {
            var data = {
                raw_id: 0,
                product_id: productid,
                part_id: partid,
                qty: 0,
                type: 0,
                p1: 0,
                p2: 0,
                p3: 0,
                p4: 0,
                guige: "",
                tfl_weight: 0,
                SurfaceArea: ""
            };

            if (!ValidateModel("#box_add4 ul.mc", function (error) {
                alert(error);
            })) {
                return;
            };
            var data_main = GetFormData("#box_add4 ul.mc");
            data["raw_id"] = data_main["raw_id"];
            data["qty"] = data_main["qty"];
            data["tfl_weight"] = data_main["tfl_weight"];

            var rawtype = $("input[name='rawtype']:checked").val();
            if (rawtype == undefined) {
                alert("请选择材料型号！");
                return;
            }
            data["type"] = parseInt(rawtype);
            switch(rawtype)
            {
                case "1":
                    if (!ValidateModel("#box_add4 div.xh ul:first", function (error) {
                        alert(error);
                    })) {
                        return;
                    };
                    var data1 = GetFormData("#box_add4 div.xh ul:first");
                    data["p1"] = data1["p1"];
                    data["p2"] = data1["p2"];
                    data["p3"] = data1["p3"];
                    break;
                case "2":
                    if (!ValidateModel("#box_add4 div.xh ul:nth-child(3)", function (error) {
                        alert(error);
                    })) {
                        return;
                    };
                    var data2 = GetFormData("#box_add4 div.xh ul:nth-child(3)");
                    data["p1"] = data2["p1"];
                    data["p2"] = data2["p2"];
                    break;
                case "3":
                    if (!ValidateModel("#box_add4 div.xh ul:nth-child(4)", function (error) {
                        alert(error);
                    })) {
                        return;
                    };
                    var data3 = GetFormData("#box_add4 div.xh ul:nth-child(4)");
                    data["p1"] = data3["p1"];
                    data["p2"] = data3["p2"];
                    data["p3"] = data3["p3"];
                    break;
                case "4":
                    if (!ValidateModel("#box_add4 div.xh ul:nth-child(5)", function (error) {
                        alert(error);
                    })) {
                        return;
                    };
                    var data4 = GetFormData("#box_add4 div.xh ul:nth-child(5)");
                    data["p1"] = data4["p1"];
                    data["p2"] = data4["p2"];
                    data["p3"] = data4["p3"];
                    data["p4"] = data4["p4"];
                    break;
                case "5":
                    if (!ValidateModel("#box_add4 div.xh ul:nth-child(6)", function (error) {
                        alert(error);
                    })) {
                        return;
                    };
                    break;
                case "6":
                    if (!ValidateModel("#box_add4 div.xh ul:nth-child(7)", function (error) {
                        alert(error);
                    })) {
                        return;
                    };

                    break;
                default:
                    break;
            }
            PostApi("/Product/AddPartMetarial", data, function (result) {
                if (result.code == 0) {
                    alert("添加成功！");
                } else {
                    alert(result.ErrorMessage);
                }
            }, function () {
                alert("添加失败！");
            });
        }
    </script>
</body>
</html>

